package com.mgq.juc.design.guard.v2;

import lombok.extern.slf4j.Slf4j;

/**
 * @author MaGuangQi
 * 邮递员类,负责投递邮件
 * @date 2021-12-16 10:40
 **/
@Slf4j
public class PostMan extends Thread{
    /**
     * 邮箱的id
     */
    private int id;

    /**
     * 投递的邮件
     */
    private String mail;

    public PostMan(int id, String mail) {
        this.id=id;
        this.mail = mail;
    }

    @Override
    public void run() {
        GuardedObject guardedObject = MailBoxes.getMail(id);
        log.debug("送信件,id:{},内容是:{}",id, this.mail);
        guardedObject.complete(mail);

    }
}
